<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/html; charset=UTF-8"
		import="org.hibernate.Criteria,
				org.hibernate.Session,
				org.hibernate.criterion.Restrictions,
				fr.dauphine.bookstore.modele.*,
				fr.dauphine.bookstore.hibernate.HibernateUtil,
				fr.dauphine.bookstore.frontoffice.SessionUtil,
				fr.dauphine.bookstore.commun.FormatUtil,
				java.util.Map.Entry" %>
<%
	String id = request.getParameter("id");

	Session hSession = HibernateUtil.getSessionFactory().getCurrentSession();
	Criteria crit = hSession.createCriteria(Order.class);
	crit.add(Restrictions.eq("id", Long.valueOf(id)));
	
	Order order = (Order) crit.uniqueResult();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
	<title>Bookstore :: Commande n°<%=order%></title>
	<%@include file="include.jsp" %>
</head>

<body>
	<div>
		<h2>
			Commande n°<%=order%>
			-
			<% if (order.calculateStatus() == Order.STATUS_SHIPPED) { %>
				Envoyee le <%=FormatUtil.formatDate(order.getShippingDate())%>
			<% } else { %>
				Reglee le <%=FormatUtil.formatDate(order.getOrderDate())%>
			<% } %>
		</h2>
		<div class="boite bleue">
			<table>
				<tr>
					<th class="large">Titre</th>
					<th class="moyenne">Prix unitaire</th>
					<th class="etroite">Quantite</th>
					<th class="moyenne">Total</th>
				</tr>
				<% for (Entry<Book, Integer> entryCommun : order.getBooks().entrySet()) { %>
				<tr>
					<td><%=entryCommun.getKey()%></td>
					<td class="centree"><%=FormatUtil.formatPrice(entryCommun.getKey().getPrice())%></td>
					<td class="centree"><%=entryCommun.getValue()%></td>
					<td class="centree"><%=FormatUtil.formatPrice(order.calculateSubTotal(entryCommun.getKey()))%></td>
				</tr>
				<% } %>
				<tr>
					<td colspan="3" style="text-align:right;"><strong>Total commande</strong></td>
					<td class="centree"><%=FormatUtil.formatPrice(order.calculateTotal())%></td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>
